import 'package:flutter/material.dart';

class HomePage extends StatelessWidget {

  Widget build(BuildContext context) =>
      DefaultTextStyle(
        child: Container(
          child: Text('Home Page'),
          color: Colors.white,
          alignment: Alignment.center,
        ),
        style: Theme
            .of(context)
            .textTheme
            .display1,
      );
}

class SignUpPage extends StatelessWidget {

  @override
  Widget build(BuildContext context) {
    return Navigator(
        initialRoute: ('signup/personal_info'),
        onGenerateRoute: (RouteSettings settings) {
          WidgetBuilder builder;
          switch (settings.name) {
            case 'signup/personal_info':
              builder = (BuildContext _) => CollectPersonalInfoPage();
              break;
            case 'signup/choose_credentials':
              builder = (BuildContext _) =>
                  ChooseCredentialsPage(
                    onSignupComplete: () {
                      Navigator.pop(context);
                    },
                  );
              break;
            default:
              throw Exception('Invalid route: ${settings.name}');
          }
          return MaterialPageRoute(builder: builder, settings: settings);
        });
  }
}

class CollectPersonalInfoPage extends StatelessWidget {

  @override
  Widget build(BuildContext context) {
    return DefaultTextStyle(
      style: Theme
          .of(context)
          .textTheme
          .display1,
      child: GestureDetector(
        onTap: () {
          Navigator.of(context).pushReplacementNamed(
              'signup/choose_credentials');
        },
        child: Container(
          color: Colors.lightBlue,
          alignment: Alignment.center,
          child: Text('collection person info page'),
        ),
      ),
    );
  }
}


class ChooseCredentialsPage extends StatelessWidget {

  const ChooseCredentialsPage({
    this.onSignupComplete,
  });

  final VoidCallback onSignupComplete;

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: onSignupComplete,
      child: DefaultTextStyle(
        child: Container(
          color: Colors.pinkAccent,
          alignment: Alignment.center,
          child: Text('choose Credentials Page'),
        ),
        style: Theme
            .of(context)
            .textTheme
            .display1,
      ),
    );
  }

}